/**
 * Configuration of the main module.
 * @author Paweł Pawłowski <abdul-pablo@tlen.pl>
 * @author Leily Zafari
 */

#include "watering.h"
#include "messages.h"

configuration WateringControlAppC {

}

implementation {
	//basic components
	components MainC;
	components WateringControlM;

	components LedsC;
	components ActiveMessageC;
	WateringControlM.AMControl  -> ActiveMessageC ;

	//wiring of basic components and interfaces
	WateringControlM.Boot              -> MainC;
	WateringControlM.Leds              -> LedsC;

	//components and wiring for messaging

	//ValveControlMsgToValve
	components new AMSenderC(AM_VALVECONTROLMSGTOVALVE) as ValveControlAMSender;
	components new AMReceiverC(AM_VALVECONTROLMSGTOVALVE) as ValveControlAMReceiver;

	WateringControlM.ValveControl_Packet  -> ValveControlAMSender.Packet;
	WateringControlM.ValveControl_AMPacket  -> ValveControlAMSender.AMPacket;
	WateringControlM.ValveControl_AMSend  -> ValveControlAMSender.AMSend;
	WateringControlM.ValveControl_Receive  -> ValveControlAMReceiver.Receive;

	//DataRequestMsgToSink
	components new AMSenderC(AM_DATAREQUESTMSGTOSINK) as DataRequestToSinkAMSender;
	components new AMReceiverC(AM_DATAREQUESTMSGTOSINK) as DataRequestToSinkAMReceiver;

	WateringControlM.DataRequestToSink_Packet -> DataRequestToSinkAMSender.Packet;
	WateringControlM.DataRequestToSink_AMPacket -> DataRequestToSinkAMSender.AMPacket;
	WateringControlM.DataRequestToSink_AMSend -> DataRequestToSinkAMSender.AMSend;
	WateringControlM.DataRequestToSink_Receive -> DataRequestToSinkAMReceiver.Receive;

	//ValveStateMsg
	components new AMSenderC(AM_VALVESTATEMSG) as ValveStateAMSender;
	components new AMReceiverC(AM_VALVESTATEMSG) as ValveStateAMReceiver;

	WateringControlM.ValveState_Packet -> ValveStateAMSender.Packet;
	WateringControlM.ValveState_AMPacket -> ValveStateAMSender.AMPacket;
	WateringControlM.ValveState_AMSend -> ValveStateAMSender.AMSend;
	WateringControlM.ValveState_Receive -> ValveStateAMReceiver.Receive;

	//HumidityMsg
	components new AMSenderC(AM_HUMIDITYMSG) as HumidtyAMSender;
	components new AMReceiverC(AM_HUMIDITYMSG) as HumidtyAMReceiver;

	WateringControlM.Humidity_Packet -> HumidtyAMSender.Packet;
	WateringControlM.Humidity_AMPacket -> HumidtyAMSender.AMPacket;
	WateringControlM.Humidity_AMSend -> HumidtyAMSender.AMSend;
	WateringControlM.Humidity_Receive -> HumidtyAMReceiver.Receive;

	//WaterLevelMsg
	components new AMSenderC(AM_WATERLEVELMSG) as WaterLevelAMSender;
	components new AMReceiverC(AM_WATERLEVELMSG) as WaterLevelAMReceiver;

	WateringControlM.WaterLevel_Packet -> WaterLevelAMSender.Packet;
	WateringControlM.WaterLevel_AMPacket -> WaterLevelAMSender.AMPacket;
	WateringControlM.WaterLevel_AMSend -> WaterLevelAMSender.AMSend;
	WateringControlM.WaterLevel_Receive -> WaterLevelAMReceiver.Receive;

	//SystemStateMsgToGateway
	components new AMSenderC(AM_SYSTEMSTATEMSGTOGATEWAY) as SystemStateToGatewayAMSender;
	components new AMReceiverC(AM_SYSTEMSTATEMSGTOGATEWAY) as SystemStateToGatewayAMReceiver;

	WateringControlM.SystemStateToGateway_Packet -> SystemStateToGatewayAMSender.Packet;
	WateringControlM.SystemStateToGateway_AMPacket -> SystemStateToGatewayAMSender.AMPacket;
	WateringControlM.SystemStateToGateway_AMSend -> SystemStateToGatewayAMSender.AMSend;
	WateringControlM.SystemStateToGateway_Receive -> SystemStateToGatewayAMReceiver.Receive;

	//DataRequestMsgToSensorNode
	components new AMSenderC(AM_DATAREQUESTMSGTOSENSORNODE) as DataRequestToSensorNodeAMSender;
	components new AMReceiverC(AM_DATAREQUESTMSGTOSENSORNODE) as DataRequestToSensorNodeAMReceiver;

	WateringControlM.DataRequestToSensorNode_Packet -> DataRequestToSensorNodeAMSender.Packet;
	WateringControlM.DataRequestToSensorNode_AMPacket -> DataRequestToSensorNodeAMSender.AMPacket;
	WateringControlM.DataRequestToSensorNode_AMSend -> DataRequestToSensorNodeAMSender.AMSend;
	WateringControlM.DataRequestToSensorNode_Receive -> DataRequestToSensorNodeAMReceiver.Receive;

	//NoResponseMsg
	components new AMSenderC(AM_NORESPONSEMSG) as NoResponseAMSender;
	components new AMReceiverC(AM_NORESPONSEMSG) as NoResponseAMReceiver;

	WateringControlM.NoResponse_Packet -> NoResponseAMSender.Packet;
	WateringControlM.NoResponse_AMPacket -> NoResponseAMSender.AMPacket;
	WateringControlM.NoResponse_AMSend -> NoResponseAMSender.AMSend;
	WateringControlM.NoResponse_Receive -> NoResponseAMReceiver.Receive;

	//SystemAlertMsgToGateway
	components new AMSenderC(AM_SYSTEMALERTMSGTOGATEWAY) as SystemAlertToGatewayAMSender;
	components new AMReceiverC(AM_SYSTEMALERTMSGTOGATEWAY) as SystemAlertToGatewayAMReceiver;

	WateringControlM.SystemAlertToGateway_Packet -> SystemAlertToGatewayAMSender.Packet;
	WateringControlM.SystemAlertToGateway_AMPacket -> SystemAlertToGatewayAMSender.AMPacket;
	WateringControlM.SystemAlertToGateway_AMSend -> SystemAlertToGatewayAMSender.AMSend;
	WateringControlM.SystemAlertToGateway_Receive -> SystemAlertToGatewayAMReceiver.Receive;

	//#ifdef GATEWAY_MODE
	//serial messaging control
	components SerialActiveMessageC as SerialMsg;
	WateringControlM.SerialControl -> SerialMsg.SplitControl;
	WateringControlM.SerialPacket -> SerialMsg.Packet;
	WateringControlM.SerialAMPacket -> SerialMsg.AMPacket;

	//DataRequestMsgToGateway
	components new SerialAMReceiverC(AM_DATAREQUESTMSGTOGATEWAY) as DataRequestToGateway_SerialAMReceiver;
	WateringControlM.DataRequestToGateway_SerialReceive -> DataRequestToGateway_SerialAMReceiver;

	//ValveControlMsgToGateway
	components new SerialAMReceiverC(AM_VALVECONTROLMSGTOGATEWAY) as ValveControlToGateway_SerialAMReceiver;
	WateringControlM.ValveControlToGateway_SerialReceive -> ValveControlToGateway_SerialAMReceiver;

	//SystemStateMsgToGateway
	components new SerialAMSenderC(AM_SYSTEMSTATEMSGTOUSB) as SystemStateToUSB_SerialAMSender;
	WateringControlM.SystemStateToUSB_SerialMessageSend -> SystemStateToUSB_SerialAMSender;

	//SystemAlertMsgToGateway
	components new SerialAMSenderC(AM_SYSTEMALERTMSGTOUSB) as SystemAlertToUSB_SerialAMSender;
	WateringControlM.SystemAlertToUSB_SerialMessageSend -> SystemAlertToUSB_SerialAMSender;
	//#endif

	//timers
	components new TimerMilliC() as TimerSensor;
	components new TimerMilliC() as TimerSender;
	components new TimerMilliC() as TimerResponse;
	components new TimerMilliC() as TimerWateringControl;

	WateringControlM.TimerSensor  -> TimerSensor;
	WateringControlM.TimerSender  -> TimerSender;
	WateringControlM.TimerResponse -> TimerResponse;
	WateringControlM.TimerWateringControl -> TimerWateringControl;

	//sensors
	#ifdef SOIL_MODE
	components HumiditySensorC as MySensor;
	WateringControlM.SensorRead -> MySensor.Read;
	#endif


	#ifdef TANK_MODE
	components WaterLevelSensorC;
	WateringControlM.SensorRead -> WaterLevelSensorC.Read;
	#endif

	//valve module
	#ifdef VALVE_MODE
	components ValveC;
	WateringControlM.Valve -> ValveC;
	#endif

	//LKN sensor board support
	components SBoardC;
	WateringControlM.SBoard -> SBoardC;
}